<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Database Info</title>


    <!-- 引入 Element UI 的 CSS 样式 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-ui@2.15.3/lib/theme-chalk/index.css">
    <!-- 引入 Vue.js 和 Element UI 的 JavaScript -->
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/element-ui@2.15.3/lib/index.js"></script>
</head>

<body>
<div id="app" style="background-color: #E6F7FF;">
    <el-table :data="tableData" border>
        <el-table-column prop="id" label="ID"></el-table-column>
        <el-table-column prop="str" label="数据"></el-table-column>
    </el-table>

    <el-pagination
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30]"
            :page-size="pageSize"
            layout="prev,  sizes, pager, next"
            :total="total"
    ></el-pagination>


</div>

<script>
    new Vue({
        el: '#app',
        data() {
            return {
                tableData: [],
                currentPage: 1,
                pageSize: 10,
                total: 0
            };
        },
        mounted() {
            this.loadData();
        },
        methods: {
            loadData() {
                // 发起 AJAX 请求，从后端获取数据
                axios
                    .get(`/demo/page?page=${this.currentPage}&pageSize=${this.pageSize}`)
                    .then(response => {
                        this.tableData = response.data.records;
                        this.total = response.data.total;
                    })
                    .catch(error => {
                        console.error(error);
                    });
            },
            handleCurrentChange(newPage) {
                this.currentPage = newPage;
                this.loadData();
            }
        }
    });
</script>
</body>

</html>
